<?php
/**
 * Created by PhpStorm.
 * User: extraxue
 * Date: 2018/5/2
 * Time: 下午3:14
 */
session_start();
require_once ('pdo.php');
$newName=$_GET['newName'];
$newPhone=$_GET['newPhone'];
$newLeaderName=$_GET['newLeaderName'];

$keyWord=$_SESSION['keyWord'];

$sqlCheckDeptNameIsHave="select * from dept_info a where a.dept_name = '{$newName}'";
$rsCheckDeptNameIsHave=$pdo->query($sqlCheckDeptNameIsHave);
$resultCheckDeptNameIsHave=$rsCheckDeptNameIsHave->fetch(PDO::FETCH_ASSOC);


if($newLeaderName){
    $sqlDeptChangeLeaderName="update dept_info set dept_leader = '{$newLeaderName}' where uid = '{$keyWord}'";
    $pdo->exec($sqlDeptChangeLeaderName);
    echo '<script>alert("党支部书记修改成功！");location.href="deptInfo.php";</script>';
}
if($newPhone){
    $sqlDeptChangePhone="update dept_info set dept_phone = '{$newPhone}' where uid = '{$keyWord}'";
    $pdo->exec($sqlDeptChangePhone);
    echo '<script>alert("党支部联系电话修改成功！");location.href="deptInfo.php";</script>';
}
if($newName && !$resultCheckDeptNameIsHave){
    $sqlDeptChangeName="update dept_info set dept_name = '{$newName}' where uid = '{$keyWord}'";
    $pdo->exec($sqlDeptChangeName);
    echo '<script>alert("党支部名称修改成功！");location.href="deptInfo.php";</script>';
}else{
    echo '<script>alert("此党支部名称已存在，请核实后重新填写！");location.href="deptChange.php";</script>';
}


